package com.ezjie.login.core.http;

import com.alibaba.fastjson.JSON;
import com.ezjie.baselib.core.http.HttpRequestCallBack;
import com.ezjie.login.LoginActivity;
import com.ezjie.login.core.base.BaseBean;
import com.ezjie.login.db.UserInfoDB;
import com.ezjie.login.model.UserDetail;
import com.lidroid.xutils.exception.HttpException;

import android.content.Context;
import android.content.Intent;

public abstract class HttpRequestAbstractCallBack implements HttpRequestCallBack{

		private Context context;
		private boolean isCheckLogin;

		public HttpRequestAbstractCallBack(Context context, boolean isCheckLogin) {
			this.context = context;
			this.isCheckLogin = isCheckLogin;
		}

		@Override
		public void onStartCallBack() {
			// TODO Auto-generated method stub

		}

		@Override
		public void onLoadingCallBack(long total, long current, boolean isUploading) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onSuccessCallBack(String result) {
			System.out.println(result+"9999999999999999999999");
			BaseBean bean = JSON.parseObject(result, BaseBean.class);
			if (isCheckLogin && !bean.getIs_login()) {
				UserInfoDB db = new UserInfoDB(context);
				UserDetail queryLoginUser = db.queryLoginUser();
				queryLoginUser.islogin = 0;
				db.update(queryLoginUser);
				context.startActivity(new Intent(context, LoginActivity.class));
				return;
			}

		}

		@Override
		public void onFailureCallBack(HttpException error, String msg) {

		}
	}


